package net.xdclass.anno;

import com.alibaba.fastjson.JSON;
import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.aspectj.lang.reflect.MethodSignature;
import org.springframework.stereotype.Component;

import java.lang.reflect.Method;

@Aspect
@Component
@Slf4j
public class MyJiaMiAnnAop {


//    @Pointcut("@annotation(net.xdclass.anno.MyAnnotation)")
//    private void pointcut(){
//
//    }
//
//    @Around(value="pointcut()")
//    public Object aroud(ProceedingJoinPoint joinPoint) throws Throwable {
//        Object[] args = joinPoint.getArgs();
//        Object result = joinPoint.proceed(args);
//        log.info("请求参数：{}", JSON.toJSON(args));
//        log.info("返回结果：{}",JSON.toJSON(result));
//        return result;
//    }
@Around("@annotation(net.xdclass.anno.MyJiaMiAnn)")
public String encryptPoint(ProceedingJoinPoint joinPoint) throws Throwable {
    Object resultVo =  joinPoint.proceed();

    // 获取注解
    MethodSignature methodSignature = (MethodSignature) joinPoint.getSignature();
    Method method = methodSignature.getMethod();
    MyJiaMiAnn annotation = method.getAnnotation(MyJiaMiAnn.class);

    String encrypt = null;
    // 如果被标识了，则进行加密
    if(annotation != null){
        // 进行加密
        switch (annotation.value()){
            case "加密一":
                encrypt = "数据已经经过加密的处理了加密1";
                break;
            case "加密2":
                encrypt = "数据已经经过加密的处理了加密2";
                break;

        }

    }

    return encrypt;
}


}
